const fs = require('fs')
const zlib = require('zlib')

// 创建一个 gzip 压缩流
const gzip = zlib.createGzip()

// 创建一个gunzip流，用于解压缩数据
const gunzip = zlib.createGunzip()

const readStream = fs.createReadStream(
  './example.txt',
  'utf8'
)

const writeStream = fs.createWriteStream(
  './example2.txt',
)

// 从readStream读取数据，通过gzip压缩，然后将压缩后的数据写入writeStream
readStream.pipe(gzip).pipe(writeStream)

/*
  //从readStream读取数据,解压缩,并将数据写入到一个新的文件中
  readStream.pipe(gunzip).pipe(writeStream)
*/